package com.naiterui.ehp.bs.cms.common.utils;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.naiterui.ehp.bp.security.utils.BaseJwtUser;
import java.util.Date;
import java.util.List;
import java.util.Set;
import lombok.Builder;
import lombok.Getter;
import org.springframework.security.core.GrantedAuthority;

@Getter
public class JwtUser extends BaseJwtUser {

  @JsonIgnore
  protected final boolean admin;

  private final String name;

  private final String avatar;

  private final String email;

  private final String mobile;

  private final String deptName;

  @JsonIgnore
  private final Date lastPasswordResetDate;

  /**
   * 角色ID列表
   */
  private final List<Long> roleIdList;

  private final Set<String> permissions;

  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
  private final Date createdAt;

  @Builder(toBuilder = true)
  public JwtUser(Long id, String username, String password, boolean enabled,
      Set<GrantedAuthority> authorities, boolean admin, String name, String avatar, String email, String mobile, String deptName,
      Date lastPasswordResetDate, List<Long> roleIdList, Set<String> permissions, Date createdAt) {
    super(id, username, password, enabled, authorities);
    this.admin = admin;
    this.name = name;
    this.avatar = avatar;
    this.email = email;
    this.mobile = mobile;
    this.deptName = deptName;
    this.lastPasswordResetDate = lastPasswordResetDate;
    this.roleIdList = roleIdList;
    this.permissions = permissions;
    this.createdAt = createdAt;
  }
}
